<?php
    echo "<h2> Master Template </h2>";
    if(!empty($wrong))
    { echo "<span class='red'>Template's name cannot be twin</span>"; }
    if(!empty($empty))
    { echo "<span class='red'>Template's name or Template's path cannot be empty</span>"; }

    
     
        
        echo "<form>";
            echo "<label id='left'> Template : </label>";
            echo "<label id='center'><input id='test' name ='data[Template][name]' type='text' > &nbsp Path :";
            echo "<label id='center'><input id='test' name ='data[Template][path]' type='text' > &nbsp";
            echo $ajax->submit('Add', array('div' => false, 'class' => 'submitbutton', 
                                'url' => array('controller'=> 'templates','action' => 'index_admin'), 
                                'update' => 'masterisi', 'condition'=>"document.getElementById('test').value!=''")
                                );
            echo "</label>";
        echo "</form><br style='margin-bottom:2px'>";
        
                
    $i=1;
    echo "<label id='left'>   <b>ID</b>     </label>";   
    echo "<label id='center'> <b>Name</b>   </label>";
    echo "<label id='center'> <b>Path</b>   </label>";
    echo "<label id='action'> <b>Action</b> </label>";
    echo "<br><hr width='640px'>";    
    foreach($templates as $data)
    {
        echo "<div id='display".$i."'>";     
            echo "<label id='left'>".$data['Template']['id']."</label>";
            echo "<label id='center'>".$data['Template']['name']."</label>";  
            echo "<label id='center'>".$data['Template']['path']."</label>";  
            echo "<label id='action'>";               
            echo "<a href='Javascript:swap3(".$i.");' class='sky'>[ Edit ]</a>";
            echo " &nbsp ";               
            echo $ajax->link( '[ Delete ]', 
                    array('controller' => 'templates', 'action' => 'delete_admin',$data['Template']['id']),
                    array('update' => 'masterisi','class'=>'sky'),
                    "Are you sure ?"
                    );  
            echo "</label>";
            echo "<br style='margin-bottom:2px'>";
        echo "</div>";        
        
        echo "<div id='myform".$i."' style='display:none'>";        
        echo "<form>";
            echo "<input name ='data[Template][id]' type='hidden' value='".$data['Template']['id']."'>";
            echo "<label id='left'>".$data['Template']['id']."</label>";
            echo "<label id='center'><input name ='data[Template][name]' type='text' value='".$data['Template']['name']."'> &nbsp Path :";
            echo "<label id='center'><input name ='data[Template][path]' type='text' value='".$data['Template']['path']."'> &nbsp";
            echo $ajax->submit('Save', array('div' => false, 'class' => 'submitbutton', 
                                'url' => array('controller'=> 'templates','action' => 'index_admin'), 
                                'update' => 'masterisi')
                                );
            echo "</label>";
            echo "<br style='margin-bottom:2px'>";
        echo "</form>";
        echo "</div>";        
        
        $i++;
    }
    
?>